
!------------------------------------------------------------------------!
!  The Community Multiscale Air Quality (CMAQ) system software is in     !
!  continuous development by various groups and is based on information  !
!  from these groups: Federal Government employees, contractors working  !
!  within a United States Government contract, and non-Federal sources   !
!  including research institutions.  These groups give the Government    !
!  permission to use, prepare derivative works of, and distribute copies !
!  of their work in the CMAQ system to the public and to permit others   !
!  to do so.  The United States Environmental Protection Agency          !
!  therefore grants similar permission to use the CMAQ system software,  !
!  but users are requested to provide copies of derivative works or      !
!  products designed to operate in the CMAQ system to the United States  !
!  Government without restrictions as to use by others.  Software        !
!  that is used with the CMAQ system but distributed under the GNU       !
!  General Public License or the GNU Lesser General Public License is    !
!  subject to their copyright restrictions.                              !
!------------------------------------------------------------------------!


      SUBROUTINE HRG2( DTC )
C**********************************************************************
C
C  FUNCTION: To solve for the concentration of HO, HO2, HONO, and
C            HNO4 alebraically.
C
C  PRECONDITIONS: For the SAPRC07TIC_AE7I_AQ mechanism
C
C  KEY SUBROUTINES/FUNCTIONS CALLED: None
C
C  REVISION HISTORY: Created by EBI solver program, Jun  8, 2022
C
C   18 Jul 14 B.Hutzell: revised to use real(8) variables
C**********************************************************************
      USE HRDATA

      IMPLICIT NONE


C..INCLUDES: None


C..ARGUMENTS:
      REAL( 8 ), INTENT( IN ) :: DTC                      ! Time step

C..PARAMETERS: None


C..EXTERNAL FUNCTIONS: NONE


C..SAVED LOCAL VARIABLES:
!     CHARACTER( 16 ), SAVE :: PNAME = 'HRG2'             ! Program name


C..SCRATCH LOCAL VARIABLES:
      REAL( 8 ) ::    O1D_S                 ! sum of O1D loss frequencies
      REAL( 8 ) ::    OH_S                  ! stoich coeff for OH from O1D+H2O or H2
      REAL( 8 ) ::    HO2_S                 ! stoich coeff for HO2 from O1D+H2 rxn
      REAL( 8 ) ::    XOH_S                 ! stoich coeff for OH & HONO from NO2EX loss rxn
      REAL( 8 ) ::    R4_19                 ! production of OH from HONO
      REAL( 8 ) ::    R19_4                 ! production of HONO from OH
      REAL( 8 ) ::    R4_5                  ! production of OH from HO2
      REAL( 8 ) ::    R5_4                  ! production of HO2 from OH
      REAL( 8 ) ::    R5_21                 ! production of HO2 from HNO4
      REAL( 8 ) ::    R21_5                 ! production of HNO4 from HO2
      REAL( 8 ) ::    P4, P5, P19, P21      ! species production form other paths
      REAL( 8 ) ::    L4, L5, L19, L21      ! species loss terms

      REAL( 8 ) ::    A, B, C               ! coeffs of quadratic eq. for HO2
      REAL( 8 ) ::    Q                     ! intermediate term

      REAL( 8 ) ::    T1, T2, T3            ! intermediate terms

      REAL( 8 ) ::    L21_INV               ! reciprocal of HNO4 loss term

C**********************************************************************


c..stoichiometric coefficient for production of HOX from O3 via O1D
      O1D_S =                 RKI(    20 )                         ! O1D=0.2000D+01*OH
     &      +                 RKI(    21 )                         ! O1D=O3P

      OH_S =    2.0000D+00 * RKI(    20 )                         ! O1D=0.2000D+01*OH

      OH_S  = OH_S / O1D_S


c..Production of HO from HO2 (r4,5 terms )
      R4_5 =                 RKI(    31 ) * YC ( NO           )   ! HO2+NO=OH+NO2
     &     +                 RKI(    36 ) * YC ( O3           )   ! HO2+O3=OH
     &     +    8.0000D-01 * RKI(    39 ) * YC ( NO3          )   ! HO2+NO3=0.8000D+...
     &     +    4.4000D-01 * RKI(    67 ) * YC ( MECO3        )   ! HO2+MECO3=...
     &     +    4.4000D-01 * RKI(    77 ) * YC ( RCO3         )   ! HO2+RCO3=0.4400D+...
     &     +    4.4000D-01 * RKI(    88 ) * YC ( BZCO3        )   ! HO2+BZCO3=...
     &     +    4.4000D-01 * RKI(   270 ) * YC ( HCOCO3       )   ! HO2+HCOCO3=...
     &     +                 RKI(   595 ) * YC ( CL           )   ! HO2+CL=OH+CLO
     &     +    1.2000D-01 * RKI(   711 ) * YC ( ISOPO2       )   ! HO2+ISOPO2=...
     &     +    4.4000D-01 * RKI(   786 ) * YC ( MACO3        )   ! HO2+MACO3=...
     &     +    1.7500D-01 * RKI(   814 ) * YC ( IEPOXOO      )   ! HO2+IEPOXOO=...

      R4_5  = R4_5 * DTC

c..Production of HO from HONO (r4,19 terms )
      R4_19 =                 RKI(    23 )                         ! HONO=OH+NO

      R4_19 = R4_19 * DTC

c..Remaining HO production
      P4 =   OH_S  *       RXRAT(    18 )      ! O1D=0.2000D+01*OH
     &   +                 RXRAT(    28 )      ! HNO3=OH+NO2
     &   +    3.9000D-01 * RXRAT(    34 )      ! HNO4=0.3900D+00*OH+0.6100D+...
     &   +    2.0000D+00 * RXRAT(    41 )      ! HO2H=0.2000D+01*OH
     &   +                 RXRAT(   114 )      ! xOH+NO=OH+NO
     &   +                 RXRAT(   116 )      ! xOH+NO3=OH+NO3
     &   +    5.0000D-01 * RXRAT(   117 )      ! xOH+MEO2=0.5000D+00*OH+MEO2
     &   +    5.0000D-01 * RXRAT(   118 )      ! xOH+RO2C=0.5000D+00*OH+RO2C
     &   +    5.0000D-01 * RXRAT(   119 )      ! xOH+RO2XC=0.5000D+00*OH+RO2XC
     &   +                 RXRAT(   120 )      ! xOH+MECO3=OH+MECO3
     &   +                 RXRAT(   121 )      ! xOH+RCO3=OH+RCO3
     &   +                 RXRAT(   122 )      ! xOH+BZCO3=OH+BZCO3
     &   +                 RXRAT(   123 )      ! xOH+MACO3=OH+MACO3
     &   +                 RXRAT(   213 )      ! COOH=OH+HO2+HCHO
     &   +                 RXRAT(   215 )      ! ROOH=OH+HO2+RCHO
     &   +                 RXRAT(   217 )      ! R6OOH=OH+0.1420D+00*HO2+...
     &   +                 RXRAT(   219 )      ! RAOOH=OH+HO2+0.5000D+...
     &   +    8.2600D-01 * RXRAT(   237 )      ! AFG1+O3=0.8260D+00*OH+...
     &   +    8.2600D-01 * RXRAT(   240 )      ! AFG2+O3=0.8260D+00*OH+...
     &   +    4.7100D-01 * RXRAT(   243 )      ! AFG3+O3=0.4710D+00*OH+...
     &   +    2.0800D-01 * RXRAT(   244 )      ! MACR+O3=0.2080D+00*OH+...
     &   +    1.6400D-01 * RXRAT(   246 )      ! MVK+O3=0.1640D+00*OH+...
     &   +    2.8500D-01 * RXRAT(   250 )      ! IPRD+O3=0.2850D+00*OH+...
     &   +    3.3000D-01 * RXRAT(   260 )      ! ACROLEIN+O3=0.3300D+00*OH+...
     &   +    1.7800D-01 * RXRAT(   263 )      ! ACROLEIN=0.1780D+00*OH+...
     &   +                 RXRAT(   265 )      ! CCOOOH=OH+CO2+MEO2
     &   +                 RXRAT(   267 )      ! RCOOOH=OH+xCCHO+yROOH+CO2+xHO2
     &   +    1.6000D-01 * RXRAT(   525 )      ! ETHENE+O3=0.1600D+00*OH+...
     &   +    3.5000D-01 * RXRAT(   529 )      ! PROPENE+O3=0.3500D+00*OH+...
     &   +    8.0000D-02 * RXRAT(   533 )      ! BUTADIENE13+O3=0.8000D-...
     &   +    2.6600D-01 * RXRAT(   536 )      ! ISOPRENE+O3=0.2660D+00*OH+...
     &   +    7.2800D-01 * RXRAT(   539 )      ! APIN+O3=0.7280D+00*OH+...
     &   +    5.0000D-01 * RXRAT(   543 )      ! ACETYLENE+O3=0.5000D+00*OH+...
     &   +    1.2800D-01 * RXRAT(   558 )      ! OLE1+O3=0.1280D+00*OH+...
     &   +    4.4300D-01 * RXRAT(   562 )      ! OLE2+O3=0.4430D+00*OH+...
     &   +    4.9900D-01 * RXRAT(   569 )      ! TERP+O3=0.4990D+00*OH+...
     &   +    4.9900D-01 * RXRAT(   584 )      ! SESQ+O3=0.4990D+00*OH+...
     &   +                 RXRAT(   605 )      ! HOCL=OH+CL
     &   +    4.1400D-01 * RXRAT(   621 )      ! ROOH+CL=0.4140D+00*OH+HCL+...
     &   +    1.4500D-01 * RXRAT(   622 )      ! R6OOH+CL=0.1450D+00*OH+HCL+...
     &   +    1.3900D-01 * RXRAT(   623 )      ! RAOOH+CL=0.1390D+00*OH+...
     &   +                 RXRAT(   717 )      ! HPALD=OH+HO2+0.5000D+...
     &   +    7.9000D-01 * RXRAT(   733 )      ! HC5+O3=0.7900D+00*OH+...
     &   +    7.3000D-01 * RXRAT(   740 )      ! ISOPND+O3=0.7300D+00*OH+...
     &   +    3.4000D-01 * RXRAT(   747 )      ! ISOPNB+O3=0.3400D+00*OH+...
     &   +    8.5000D-01 * RXRAT(   762 )      ! NIT1+O3=0.8500D+00*OH+...
     &   +    9.5000D-01 * RXRAT(   814 )      ! HO2+IEPOXOO=0.1125D+01*OH+...
     &   +    1.2500D-01 * RXRAT(   815 )      ! IEPOXOO+NO=0.1250D+00*OH+...
     &   +    6.3000D-02 * RXRAT(   816 )      ! IEPOXOO+MEO2=0.6300D-01*OH+...
     &   +    6.3000D-02 * RXRAT(   817 )      ! IEPOXOO+RO2C=0.6300D-01*OH+...
     &   +    1.2500D-01 * RXRAT(   818 )      ! IEPOXOO+MECO3=0.1250D+...
     &   +                 RXRAT(   819 )      ! ISOPOOH=OH+0.9100D+00*HO2+...
     &   +    3.3000D-01 * RXRAT(   825 )      ! MACR=0.3300D+00*OH+0.6700D+...
     &   +                 RXRAT(   838 )      ! MACROO=OH+CO+HACET
     &   +                 RXRAT(   849 )      ! xOH+IMACO3=OH+IMACO3

      P4 = YC0( OH ) + P4 * DTC

c..Production of HO2 from OH ( r5,4 terms )
      R5_4 =                 RKI(    26 ) * YC ( NO3          )   ! OH+NO3=HO2+NO2
     &     +                 RKI(    29 ) * YC ( CO           )   ! OH+CO=HO2+CO2
     &     +                 RKI(    30 ) * YC ( O3           )   ! OH+O3=HO2
     &     +                 RKI(    42 ) * YC ( HO2H         )   ! OH+HO2H=HO2
     &     +                 RKI(    44 ) * YC ( SO2          )   ! OH+SO2=HO2+SULF+...
     &     +                 RKI(    45 )                         ! OH=HO2
     &     +                 RKI(   196 ) * YC ( HCHO         )   ! OH+HCHO=HO2+CO
     &     +                 RKI(   208 ) * YC ( MEOH         )   ! OH+MEOH=HO2+HCHO
     &     +                 RKI(   209 ) * YC ( HCOOH        )   ! OH+HCOOH=HO2+CO2
     &     +    1.4800D-01 * RKI(   218 ) * YC ( RAOOH        )   ! OH+RAOOH=0.1480D+...
     &     +    7.0000D-01 * RKI(   222 ) * YC ( GLY          )   ! OH+GLY=0.7000D+...
     &     +    4.7200D-01 * RKI(   253 ) * YC ( PRD2         )   ! OH+PRD2=0.4720D+...
     &     +    1.8900D-01 * RKI(   255 ) * YC ( RNO3         )   ! OH+RNO3=0.1890D+...
     &     +    3.0000D-01 * RKI(   542 ) * YC ( ACETYLENE    )   ! OH+ACETYLENE=...
     &     +    5.7000D-01 * RKI(   544 ) * YC ( BENZENE      )   ! OH+BENZENE=...
     &     +    1.8100D-01 * RKI(   545 ) * YC ( TOLUENE      )   ! OH+TOLUENE=...
     &     +    1.5900D-01 * RKI(   546 ) * YC ( MXYL         )   ! OH+MXYL=0.1590D+...
     &     +    1.6100D-01 * RKI(   547 ) * YC ( OXYL         )   ! OH+OXYL=0.1610D+...
     &     +    1.5900D-01 * RKI(   548 ) * YC ( PXYL         )   ! OH+PXYL=0.1590D+...
     &     +    2.2000D-02 * RKI(   549 ) * YC ( TMBENZ124    )   ! OH+TMBENZ124=...
     &     +    9.5000D-01 * RKI(   550 ) * YC ( ETOH         )   ! OH+ETOH=0.9500D+...
     &     +    1.2300D-01 * RKI(   565 ) * YC ( ARO1         )   ! OH+ARO1=0.1230D+...
     &     +    7.7000D-02 * RKI(   566 ) * YC ( ARO2MN       )   ! OH+ARO2MN=...
     &     +    7.7000D-02 * RKI(   567 ) * YC ( NAPHTHAL     )   ! OH+NAPHTHAL=...
     &     +    7.5000D-01 * RKI(   796 ) * YC ( HOCCHO       )   ! OH+HOCCHO=...
     &     +    8.2500D-01 * RKI(   797 ) * YC ( HACET        )   ! OH+HACET=0.8250D+...
     &     +    5.0000D-01 * RKI(   809 ) * YC ( DHMOB        )   ! OH+DHMOB=0.5000D+...
     &     +                 RKI(   820 ) * YC ( RNO3I        )   ! OH+RNO3I=HO2+NO2+...
     &     +    1.9000D-01 * RKI(   877 ) * YC ( IMAPAN       )   ! OH+IMAPAN=...
     &     +    1.8900D-01 * RKI(   882 ) * YC ( MTNO3        )   ! OH+MTNO3=0.1890D+...

      R5_4  = R5_4 * DTC

c..Production of HO2 from HNO4 (r5,21 term )
      R5_21 =                 RKI(    33 )                         ! HNO4=HO2+NO2
     &      +    6.1000D-01 * RKI(    34 )                         ! HNO4=0.6100D+...

      R5_21 = R5_21 * DTC

c..Remaining HO2 production terms
      P5 =                 RXRAT(    46 )      ! MEO2+NO=HO2+HCHO+NO2
     &   +                 RXRAT(    49 )      ! MEO2+NO3=HO2+HCHO+NO2
     &   +    2.0000D+00 * RXRAT(    51 )      ! MEO2+MEO2=0.2000D+01*HO2+...
     &   +    5.0000D-01 * RXRAT(    55 )      ! RO2C+MEO2=0.5000D+00*HO2+...
     &   +    5.0000D-01 * RXRAT(    60 )      ! RO2XC+MEO2=0.5000D+00*HO2+...
     &   +    9.0000D-01 * RXRAT(    69 )      ! MECO3+MEO2=0.9000D+00*HO2+...
     &   +                 RXRAT(    79 )      ! RCO3+MEO2=HO2+HCHO+RO2C+...
     &   +                 RXRAT(    90 )      ! BZCO3+MEO2=HO2+HCHO+RO2C+...
     &   +                 RXRAT(   104 )      ! xHO2+NO=HO2+NO
     &   +                 RXRAT(   106 )      ! xHO2+NO3=HO2+NO3
     &   +    5.0000D-01 * RXRAT(   107 )      ! xHO2+MEO2=0.5000D+00*HO2+MEO2
     &   +    5.0000D-01 * RXRAT(   108 )      ! xHO2+RO2C=0.5000D+00*HO2+RO2C
     &   +    5.0000D-01 * RXRAT(   109 )      ! xHO2+RO2XC=0.5000D+00*HO2+...
     &   +                 RXRAT(   110 )      ! xHO2+MECO3=HO2+MECO3
     &   +                 RXRAT(   111 )      ! xHO2+RCO3=HO2+RCO3
     &   +                 RXRAT(   112 )      ! xHO2+BZCO3=HO2+BZCO3
     &   +                 RXRAT(   113 )      ! xHO2+MACO3=HO2+MACO3
     &   +    2.0000D+00 * RXRAT(   194 )      ! HCHO=0.2000D+01*HO2+CO
     &   +                 RXRAT(   197 )      ! HCHO+NO3=HO2+HNO3+CO
     &   +                 RXRAT(   199 )      ! CCHO=HO2+CO+MEO2
     &   +                 RXRAT(   202 )      ! RCHO=HO2+xHO2+yROOH+xCCHO+...
     &   +                 RXRAT(   213 )      ! COOH=HO2+OH+HCHO
     &   +                 RXRAT(   215 )      ! ROOH=HO2+OH+RCHO
     &   +    1.4200D-01 * RXRAT(   217 )      ! R6OOH=0.1420D+00*HO2+OH+...
     &   +                 RXRAT(   219 )      ! RAOOH=HO2+OH+0.5000D+...
     &   +    2.0000D+00 * RXRAT(   220 )      ! GLY=0.2000D+01*HO2+0.2000D+...
     &   +    7.0000D-01 * RXRAT(   223 )      ! GLY+NO3=0.7000D+00*HO2+...
     &   +                 RXRAT(   224 )      ! MGLY=HO2+CO+MECO3
     &   +    5.2200D-01 * RXRAT(   237 )      ! AFG1+O3=0.5220D+00*HO2+...
     &   +    1.0230D+00 * RXRAT(   238 )      ! AFG1=0.1023D+01*HO2+...
     &   +    5.2200D-01 * RXRAT(   240 )      ! AFG2+O3=0.5220D+00*HO2+...
     &   +    5.5400D-01 * RXRAT(   243 )      ! AFG3+O3=0.5540D+00*HO2+...
     &   +    1.0800D-01 * RXRAT(   244 )      ! MACR+O3=0.1080D+00*HO2+...
     &   +    6.4000D-02 * RXRAT(   246 )      ! MVK+O3=0.6400D-01*HO2+...
     &   +    4.0000D-01 * RXRAT(   250 )      ! IPRD+O3=0.4000D+00*HO2+...
     &   +    1.2330D+00 * RXRAT(   252 )      ! IPRD=0.1233D+01*HO2+...
     &   +    3.4400D-01 * RXRAT(   256 )      ! RNO3=0.3440D+00*HO2+...
     &   +    2.0000D+00 * RXRAT(   257 )      ! HOCCHO=0.2000D+01*HO2+CO+HCHO
     &   +    8.3000D-01 * RXRAT(   260 )      ! ACROLEIN+O3=0.8300D+00*HO2+...
     &   +    1.0660D+00 * RXRAT(   263 )      ! ACROLEIN=0.1066D+01*HO2+...
     &   +                 RXRAT(   268 )      ! HCOCO3+NO=HO2+CO+CO2+NO2
     &   +                 RXRAT(   269 )      ! HCOCO3+NO2=HO2+CO+CO2+NO3
     &   +                 RXRAT(   484 )      ! zRNO3+NO3=HO2+PRD2+NO3
     &   +    5.0000D-01 * RXRAT(   485 )      ! zRNO3+MEO2=0.5000D+00*HO2+...
     &   +    5.0000D-01 * RXRAT(   486 )      ! zRNO3+RO2C=0.5000D+00*HO2+...
     &   +    5.0000D-01 * RXRAT(   487 )      ! zRNO3+RO2XC=0.5000D+00*HO2+...
     &   +                 RXRAT(   488 )      ! zRNO3+MECO3=HO2+PRD2+MECO3
     &   +                 RXRAT(   489 )      ! zRNO3+RCO3=HO2+PRD2+RCO3
     &   +                 RXRAT(   490 )      ! zRNO3+BZCO3=HO2+PRD2+BZCO3
     &   +                 RXRAT(   491 )      ! zRNO3+MACO3=HO2+PRD2+MACO3
     &   +                 RXRAT(   494 )      ! zMTNO3+NO3=HO2+PRD2+NO3
     &   +    5.0000D-01 * RXRAT(   495 )      ! zMTNO3+MEO2=0.5000D+00*HO2+...
     &   +    5.0000D-01 * RXRAT(   496 )      ! zMTNO3+RO2C=0.5000D+00*HO2+...
     &   +    5.0000D-01 * RXRAT(   497 )      ! zMTNO3+RO2XC=0.5000D+...
     &   +                 RXRAT(   498 )      ! zMTNO3+MECO3=HO2+PRD2+MECO3
     &   +                 RXRAT(   499 )      ! zMTNO3+RCO3=HO2+PRD2+RCO3
     &   +                 RXRAT(   500 )      ! zMTNO3+BZCO3=HO2+PRD2+BZCO3
     &   +                 RXRAT(   501 )      ! zMTNO3+MACO3=HO2+PRD2+MACO3
     &   +                 RXRAT(   502 )      ! zMTNO3+IMACO3=HO2+PRD2+IMACO3
     &   +    1.6000D-01 * RXRAT(   525 )      ! ETHENE+O3=0.1600D+00*HO2+...
     &   +    8.0000D-01 * RXRAT(   527 )      ! ETHENE+O3P=0.8000D+00*HO2+...
     &   +    1.6500D-01 * RXRAT(   529 )      ! PROPENE+O3=0.1650D+00*HO2+...
     &   +    8.0000D-02 * RXRAT(   533 )      ! BUTADIENE13+O3=0.8000D-...
     &   +    2.5000D-01 * RXRAT(   535 )      ! BUTADIENE13+O3P=0.2500D+...
     &   +    6.6000D-02 * RXRAT(   536 )      ! ISOPRENE+O3=0.6600D-01*HO2+...
     &   +    9.0000D-03 * RXRAT(   539 )      ! APIN+O3=0.9000D-02*HO2+...
     &   +    1.5000D+00 * RXRAT(   543 )      ! ACETYLENE+O3=0.1500D+...
     &   +    9.5000D-02 * RXRAT(   558 )      ! OLE1+O3=0.9500D-01*HO2+...
     &   +    9.4000D-02 * RXRAT(   562 )      ! OLE2+O3=0.9400D-01*HO2+...
     &   +    7.8000D-02 * RXRAT(   569 )      ! TERP+O3=0.7800D-01*HO2+...
     &   +    2.2700D-01 * RXRAT(   571 )      ! TERPNRO2+NO=0.2270D+00*HO2+...
     &   +    4.2000D-01 * RXRAT(   573 )      ! TERPNRO2+NO3=0.4200D+...
     &   +    7.1000D-01 * RXRAT(   574 )      ! TERPNRO2+MEO2=0.7100D+...
     &   +    2.1000D-01 * RXRAT(   575 )      ! TERPNRO2+RO2C=0.2100D+...
     &   +    2.1000D-01 * RXRAT(   576 )      ! TERPNRO2+RO2XC=0.2100D+...
     &   +    4.2000D-01 * RXRAT(   577 )      ! TERPNRO2+MECO3=0.4200D+...
     &   +    4.2000D-01 * RXRAT(   578 )      ! TERPNRO2+RCO3=0.4200D+...
     &   +    4.2000D-01 * RXRAT(   579 )      ! TERPNRO2+BZCO3=0.4200D+...
     &   +    4.2000D-01 * RXRAT(   580 )      ! TERPNRO2+MACO3=0.4200D+...
     &   +    4.2000D-01 * RXRAT(   581 )      ! TERPNRO2+IMACO3=0.4200D+...
     &   +    7.8000D-02 * RXRAT(   584 )      ! SESQ+O3=0.7800D-01*HO2+...
     &   +                 RXRAT(   608 )      ! CL=HO2+HCL
     &   +                 RXRAT(   609 )      ! HCHO+CL=HO2+HCL+CO
     &   +                 RXRAT(   611 )      ! MEOH+CL=HO2+HCHO+HCL
     &   +    5.5000D-02 * RXRAT(   615 )      ! RNO3+CL=0.5500D-01*HO2+...
     &   +    3.1400D-01 * RXRAT(   616 )      ! PRD2+CL=0.3140D+00*HO2+HCL+...
     &   +    6.3000D-01 * RXRAT(   617 )      ! GLY+CL=0.6300D+00*HO2+HCL+...
     &   +    1.4800D-01 * RXRAT(   623 )      ! RAOOH+CL=0.1480D+00*HO2+...
     &   +    8.4000D-02 * RXRAT(   626 )      ! IPRD+CL=0.8400D-01*HO2+...
     &   +                 RXRAT(   627 )      ! CLCCHO=HO2+CO+RO2C+xCL+...
     &   +                 RXRAT(   667 )      ! ACETYLENE+CL=HO2+CO
     &   +    6.8800D-01 * RXRAT(   673 )      ! ETOH+CL=0.6880D+00*HO2+HCL+...
     &   +    8.0300D-01 * RXRAT(   710 )      ! ISOPO2+NO=0.8030D+00*HO2+...
     &   +    9.5000D-01 * RXRAT(   712 )      ! ISOPO2+MEO2=0.9500D+00*HO2+...
     &   +    4.5000D-01 * RXRAT(   713 )      ! ISOPO2+RO2C=0.4500D+00*HO2+...
     &   +    9.1000D-01 * RXRAT(   714 )      ! ISOPO2+ISOPO2=0.9100D+...
     &   +    9.1000D-01 * RXRAT(   715 )      ! ISOPO2+MECO3=0.9100D+...
     &   +                 RXRAT(   716 )      ! ISOPO2=HO2+HPALD
     &   +                 RXRAT(   717 )      ! HPALD=HO2+OH+0.5000D+...
     &   +    8.0000D-01 * RXRAT(   720 )      ! NISOPO2+NO3=0.8000D+00*HO2+...
     &   +    8.0000D-01 * RXRAT(   721 )      ! NISOPO2+NO=0.8000D+00*HO2+...
     &   +    9.0000D-01 * RXRAT(   723 )      ! NISOPO2+MEO2=0.9000D+...
     &   +    4.0000D-01 * RXRAT(   724 )      ! NISOPO2+RO2C=0.4000D+...
     &   +    8.0000D-01 * RXRAT(   725 )      ! NISOPO2+NISOPO2=0.8000D+...
     &   +    8.0000D-01 * RXRAT(   726 )      ! NISOPO2+MECO3=0.8000D+...
     &   +                 RXRAT(   728 )      ! HC5OO+NO=HO2+0.2340D+...
     &   +                 RXRAT(   730 )      ! HC5OO+MEO2=HO2+0.1170D+...
     &   +    5.0000D-01 * RXRAT(   731 )      ! HC5OO+RO2C=0.5000D+00*HO2+...
     &   +                 RXRAT(   732 )      ! HC5OO+MECO3=HO2+CO2+...
     &   +    6.0000D-01 * RXRAT(   733 )      ! HC5+O3=0.6000D+00*HO2+...
     &   +    3.5000D-01 * RXRAT(   735 )      ! ISOPNOOD+NO=0.3500D+00*HO2+...
     &   +    6.7500D-01 * RXRAT(   737 )      ! ISOPNOOD+MEO2=0.6750D+...
     &   +    1.7500D-01 * RXRAT(   738 )      ! ISOPNOOD+RO2C=0.1750D+...
     &   +    3.5000D-01 * RXRAT(   739 )      ! ISOPNOOD+MECO3=0.3500D+...
     &   +    3.9000D-01 * RXRAT(   740 )      ! ISOPND+O3=0.3900D+00*HO2+...
     &   +    4.0000D-01 * RXRAT(   742 )      ! ISOPNOOB+NO=0.4000D+00*HO2+...
     &   +    7.0000D-01 * RXRAT(   744 )      ! ISOPNOOB+MEO2=0.7000D+...
     &   +    2.0000D-01 * RXRAT(   745 )      ! ISOPNOOB+RO2C=0.2000D+...
     &   +    4.0000D-01 * RXRAT(   746 )      ! ISOPNOOB+MECO3=0.4000D+...
     &   +    8.0000D-02 * RXRAT(   747 )      ! ISOPNB+O3=0.8000D-01*HO2+...
     &   +                 RXRAT(   749 )      ! NIT1NO3OOA+NO3=HO2+PROPNN+...
     &   +                 RXRAT(   750 )      ! NIT1NO3OOA+NO=HO2+PROPNN+...
     &   +                 RXRAT(   753 )      ! NIT1NO3OOA+RO2C=HO2+CO+CO2+...
     &   +    2.0000D+00 * RXRAT(   754 )      ! NIT1NO3OOA+MEO2=0.2000D+...
     &   +                 RXRAT(   755 )      ! NIT1NO3OOA+MECO3=HO2+...
     &   +    5.0000D-01 * RXRAT(   760 )      ! NIT1NO3OOB+MEO2=0.5000D+...
     &   +    4.5000D-01 * RXRAT(   762 )      ! NIT1+O3=0.4500D+00*HO2+...
     &   +    9.3400D-01 * RXRAT(   764 )      ! NIT1OHOO+NO=0.9340D+00*HO2+...
     &   +    7.0000D-01 * RXRAT(   766 )      ! NIT1OHOO+RO2C=0.7000D+...
     &   +    1.2000D+00 * RXRAT(   767 )      ! NIT1OHOO+MEO2=0.1200D+...
     &   +                 RXRAT(   768 )      ! NIT1OHOO+MECO3=HO2+CO2+...
     &   +                 RXRAT(   769 )      ! DIBOO+NO=HO2+NO2+0.5200D+...
     &   +                 RXRAT(   771 )      ! DIBOO+MEO2=HO2+0.2600D+...
     &   +    5.0000D-01 * RXRAT(   772 )      ! DIBOO+RO2C=0.5000D+00*HO2+...
     &   +                 RXRAT(   773 )      ! DIBOO+MECO3=HO2+0.5200D+...
     &   +    2.6500D-01 * RXRAT(   775 )      ! MVKOO+NO=0.2650D+00*HO2+...
     &   +    6.5000D-01 * RXRAT(   777 )      ! MVKOO+MEO2=0.6500D+00*HO2+...
     &   +    1.5000D-01 * RXRAT(   778 )      ! MVKOO+RO2C=0.1500D+00*HO2+...
     &   +    3.0000D-01 * RXRAT(   779 )      ! MVKOO+MECO3=0.3000D+00*HO2+...
     &   +    8.5000D-01 * RXRAT(   780 )      ! MACROO+NO=0.8500D+00*HO2+...
     &   +                 RXRAT(   782 )      ! MACROO+MEO2=HO2+0.4240D+...
     &   +    5.0000D-01 * RXRAT(   783 )      ! MACROO+RO2C=0.5000D+00*HO2+...
     &   +                 RXRAT(   784 )      ! MACROO+MECO3=HO2+CO2+MEO2+...
     &   +                 RXRAT(   788 )      ! MACO3+MEO2=HO2+0.2000D+...
     &   +                 RXRAT(   798 )      ! HACET=HO2+MECO3+HCHO
     &   +                 RXRAT(   800 )      ! ETHLN=HO2+HCHO+NO2+CO
     &   +                 RXRAT(   808 )      ! MACRN=HO2+NO2+CO+HACET
     &   +    8.2500D-01 * RXRAT(   815 )      ! IEPOXOO+NO=0.8250D+00*HO2+...
     &   +    9.1300D-01 * RXRAT(   816 )      ! IEPOXOO+MEO2=0.9130D+...
     &   +    4.1300D-01 * RXRAT(   817 )      ! IEPOXOO+RO2C=0.4130D+...
     &   +    8.2500D-01 * RXRAT(   818 )      ! IEPOXOO+MECO3=0.8250D+...
     &   +    9.1000D-01 * RXRAT(   819 )      ! ISOPOOH=0.9100D+00*HO2+OH+...
     &   +    6.7000D-01 * RXRAT(   825 )      ! MACR=0.6700D+00*HO2+...
     &   +                 RXRAT(   830 )      ! IMACO3+MEO2=HO2+0.2000D+...
     &   +                 RXRAT(   850 )      ! xHO2+IMACO3=HO2+IMACO3
     &   +                 RXRAT(   853 )      ! zRNO3+IMACO3=HO2+PRD2+IMACO3
     &   +    5.5000D-02 * RXRAT(   881 )      ! MTNO3+CL=0.5500D-01*HO2+...
     &   +    3.4400D-01 * RXRAT(   883 )      ! MTNO3=0.3440D+00*HO2+...

      P5 = YC0( HO2 ) + P5 * DTC

c..Production of HONO from OH (r19,4 terms )

      R19_4 =   RKI(    22 ) * YC( NO           ) * DTC      ! OH+NO=HONO

c..Remaining HONO production terms
      P19 =                 RXRAT(   231 )      ! NPHE=HONO
     &    +    5.0000D-01 * RXRAT(   884 )      ! NO2=0.5000D+00*HONO+...

      P19 = YC0( HONO ) + P19 * DTC

c..Production of HNO4 from HO2 (r21,5 term )

      R21_5 =   RKI(    32 ) * YCP( NO2          ) * DTC      ! HO2+NO2=HNO4

c..Remaining HNO4 production terms
      P21   =   YC0( HNO4 )

c..OH loss terms not in R5_4 & R19_4
      L4 =                 RKI(    24 ) * YC ( HONO         )   ! OH+HONO=NO2
     &   +                 RKI(    25 ) * YC ( NO2          )   ! OH+NO2=HNO3
     &   +                 RKI(    27 ) * YC ( HNO3         )   ! OH+HNO3=NO3
     &   +                 RKI(    35 ) * YC ( HNO4         )   ! OH+HNO4=NO2
     &   +                 RKI(    43 ) * YC ( HO2          )   ! OH+HO2=
     &   +                 RKI(   198 ) * YC ( CCHO         )   ! OH+CCHO=MECO3
     &   +                 RKI(   201 ) * YC ( RCHO         )   ! OH+RCHO=0.9650D+...
     &   +                 RKI(   204 ) * YC ( ACETONE      )   ! OH+ACETONE=RO2C+...
     &   +                 RKI(   206 ) * YC ( MEK          )   ! OH+MEK=0.9670D+...
     &   +                 RKI(   210 ) * YC ( CCOOH        )   ! OH+CCOOH=0.5090D+...
     &   +                 RKI(   211 ) * YC ( RCOOH        )   ! OH+RCOOH=RO2C+...
     &   +    7.0000D-01 * RKI(   212 ) * YC ( COOH         )   ! OH+COOH=0.3000D+...
     &   +    2.5600D-01 * RKI(   214 ) * YC ( ROOH         )   ! OH+ROOH=0.7440D+...
     &   +    1.6000D-01 * RKI(   216 ) * YC ( R6OOH        )   ! OH+R6OOH=0.8400D+...
     &   +    7.1300D-01 * RKI(   218 ) * YC ( RAOOH        )   ! OH+RAOOH=0.1480D+...
     &   +    3.0000D-01 * RKI(   222 ) * YC ( GLY          )   ! OH+GLY=0.7000D+...
     &   +                 RKI(   225 ) * YC ( MGLY         )   ! OH+MGLY=CO+MECO3
     &   +                 RKI(   228 ) * YC ( CRES         )   ! OH+CRES=0.2000D+...
     &   +                 RKI(   230 ) * YC ( NPHE         )   ! OH+NPHE=BZO
     &   +                 RKI(   233 ) * YC ( BALD         )   ! OH+BALD=BZCO3
     &   +                 RKI(   236 ) * YC ( AFG1         )   ! OH+AFG1=0.2170D+...
     &   +                 RKI(   239 ) * YC ( AFG2         )   ! OH+AFG2=0.2170D+...
     &   +                 RKI(   242 ) * YC ( AFG3         )   ! OH+AFG3=0.2060D+...
     &   +                 RKI(   249 ) * YC ( IPRD         )   ! OH+IPRD=0.2890D+...
     &   +    5.2800D-01 * RKI(   253 ) * YC ( PRD2         )   ! OH+PRD2=0.4720D+...
     &   +    8.1100D-01 * RKI(   255 ) * YC ( RNO3         )   ! OH+RNO3=0.1890D+...
     &   +                 RKI(   259 ) * YC ( ACROLEIN     )   ! OH+ACROLEIN=...
     &   +                 RKI(   264 ) * YC ( CCOOOH       )   ! OH+CCOOOH=...
     &   +                 RKI(   266 ) * YC ( RCOOOH       )   ! OH+RCOOOH=...
     &   +                 RKI(   523 )                         ! OH=MEO2
     &   +                 RKI(   524 ) * YC ( ETHENE       )   ! OH+ETHENE=xHO2+...
     &   +                 RKI(   528 ) * YC ( PROPENE      )   ! OH+PROPENE=...
     &   +                 RKI(   532 ) * YC ( BUTADIENE13  )   ! OH+BUTADIENE13=...
     &   +                 RKI(   538 ) * YC ( APIN         )   ! OH+APIN=0.7990D+...
     &   +    3.1400D-01 * RKI(   544 ) * YC ( BENZENE      )   ! OH+BENZENE=...
     &   +    5.0700D-01 * RKI(   545 ) * YC ( TOLUENE      )   ! OH+TOLUENE=...
     &   +    6.0200D-01 * RKI(   546 ) * YC ( MXYL         )   ! OH+MXYL=0.1590D+...
     &   +    6.4100D-01 * RKI(   547 ) * YC ( OXYL         )   ! OH+OXYL=0.1610D+...
     &   +    5.6300D-01 * RKI(   548 ) * YC ( PXYL         )   ! OH+PXYL=0.1590D+...
     &   +    7.4800D-01 * RKI(   549 ) * YC ( TMBENZ124    )   ! OH+TMBENZ124=...
     &   +    5.0000D-02 * RKI(   550 ) * YC ( ETOH         )   ! OH+ETOH=0.9500D+...
     &   +                 RKI(   551 ) * YC ( ALK1         )   ! OH+ALK1=xHO2+...
     &   +                 RKI(   552 ) * YC ( ALK2         )   ! OH+ALK2=0.9650D+...
     &   +                 RKI(   553 ) * YC ( ALK3         )   ! OH+ALK3=0.6950D+...
     &   +                 RKI(   554 ) * YC ( ALK4         )   ! OH+ALK4=0.8300D+...
     &   +                 RKI(   555 ) * YC ( ALK5         )   ! OH+ALK5=0.6470D+...
     &   +                 RKI(   557 ) * YC ( OLE1         )   ! OH+OLE1=0.8710D+...
     &   +                 RKI(   561 ) * YC ( OLE2         )   ! OH+OLE2=0.9120D+...
     &   +    6.7500D-01 * RKI(   565 ) * YC ( ARO1         )   ! OH+ARO1=0.1230D+...
     &   +    7.4500D-01 * RKI(   566 ) * YC ( ARO2MN       )   ! OH+ARO2MN=...
     &   +    7.4500D-01 * RKI(   567 ) * YC ( NAPHTHAL     )   ! OH+NAPHTHAL=...
     &   +                 RKI(   568 ) * YC ( TERP         )   ! OH+TERP=0.7340D+...
     &   +                 RKI(   583 ) * YC ( SESQ         )   ! OH+SESQ=0.7340D+...
     &   +                 RKI(   607 ) * YC ( HCL          )   ! OH+HCL=CL
     &   +                 RKI(   628 ) * YC ( CLCCHO       )   ! OH+CLCCHO=RCO3
     &   +                 RKI(   709 ) * YC ( ISOPRENE     )   ! OH+ISOPRENE=...
     &   +                 RKI(   727 ) * YC ( HC5          )   ! OH+HC5=HC5OO
     &   +                 RKI(   734 ) * YC ( ISOPND       )   ! OH+ISOPND=ISOPNOOD
     &   +                 RKI(   741 ) * YC ( ISOPNB       )   ! OH+ISOPNB=ISOPNOOB
     &   +                 RKI(   763 ) * YC ( NIT1         )   ! OH+NIT1=0.3450D+...
     &   +                 RKI(   774 ) * YC ( MVK          )   ! OH+MVK=MVKOO
     &   +                 RKI(   795 ) * YC ( MAPAN        )   ! OH+MAPAN=HACET+...
     &   +    7.5000D-02 * RKI(   797 ) * YC ( HACET        )   ! OH+HACET=0.8250D+...
     &   +                 RKI(   799 ) * YC ( ETHLN        )   ! OH+ETHLN=HCHO+...
     &   +                 RKI(   801 ) * YC ( PROPNN       )   ! OH+PROPNN=MGLY+NO2
     &   +                 RKI(   802 ) * YC ( ISOPNN       )   ! OH+ISOPNN=PROPNN+NO2
     &   +                 RKI(   805 ) * YC ( MVKN         )   ! OH+MVKN=0.6500D+...
     &   +                 RKI(   807 ) * YC ( MACRN        )   ! OH+MACRN=0.8000D-...
     &   +    5.0000D-01 * RKI(   809 ) * YC ( DHMOB        )   ! OH+DHMOB=0.5000D+...
     &   +    3.8700D-01 * RKI(   812 ) * YC ( ISOPOOH      )   ! OH+ISOPOOH=...
     &   +                 RKI(   813 ) * YC ( IEPOX        )   ! OH+IEPOX=IEPOXOO
     &   +    3.0000D-01 * RKI(   822 ) * YC ( NISOPOOH     )   ! OH+NISOPOOH=...
     &   +                 RKI(   823 ) * YC ( MACR         )   ! OH+MACR=0.5300D+...
     &   +    8.1000D-01 * RKI(   877 ) * YC ( IMAPAN       )   ! OH+IMAPAN=...
     &   +                 RKI(   878 ) * YC ( IMAE         )   ! OH+IMAE=
     &   +                 RKI(   879 ) * YC ( IHMML        )   ! OH+IHMML=
     &   +                 RKI(   880 ) * YC ( IMPAA        )   ! OH+IMPAA=0.8300D+...
     &   +    8.1100D-01 * RKI(   882 ) * YC ( MTNO3        )   ! OH+MTNO3=0.1890D+...

      L4    = 1.0D0 + L4 * DTC + R5_4 + R19_4

c..HO2 loss terms not included in R4_5 & R21_5 (except for HO2+HO2 )
      L5 =    2.0000D-01 * RKI(    39 ) * YC ( NO3          )   ! HO2+NO3=0.8000D+...
     &   +                 RKI(    43 ) * YC ( OH           )   ! HO2+OH=
     &   +                 RKI(    47 ) * YC ( MEO2         )   ! HO2+MEO2=COOH
     &   +                 RKI(    48 ) * YC ( MEO2         )   ! HO2+MEO2=HCHO
     &   +                 RKI(    53 ) * YC ( RO2C         )   ! HO2+RO2C=
     &   +                 RKI(    58 ) * YC ( RO2XC        )   ! HO2+RO2XC=
     &   +    5.6000D-01 * RKI(    67 ) * YC ( MECO3        )   ! HO2+MECO3=...
     &   +    5.6000D-01 * RKI(    77 ) * YC ( RCO3         )   ! HO2+RCO3=0.4400D+...
     &   +    5.6000D-01 * RKI(    88 ) * YC ( BZCO3        )   ! HO2+BZCO3=...
     &   +                 RKI(   102 ) * YC ( BZO          )   ! HO2+BZO=CRES
     &   +    1.2000D-01 * RKI(   270 ) * YC ( HCOCO3       )   ! HO2+HCOCO3=...
     &   +                 RKI(   572 ) * YC ( TERPNRO2     )   ! HO2+TERPNRO2=MTNO3
     &   +                 RKI(   594 ) * YC ( CL           )   ! HO2+CL=HCL
     &   +                 RKI(   604 ) * YC ( CLO          )   ! HO2+CLO=HOCL
     &   +    7.6000D-01 * RKI(   711 ) * YC ( ISOPO2       )   ! HO2+ISOPO2=...
     &   +                 RKI(   722 ) * YC ( NISOPO2      )   ! HO2+NISOPO2=NISOPOOH
     &   +                 RKI(   729 ) * YC ( HC5OO        )   ! HO2+HC5OO=R6OOH
     &   +                 RKI(   736 ) * YC ( ISOPNOOD     )   ! HO2+ISOPNOOD=RNO3I
     &   +                 RKI(   743 ) * YC ( ISOPNOOB     )   ! HO2+ISOPNOOB=RNO3I
     &   +                 RKI(   752 ) * YC ( NIT1NO3OOA   )   ! HO2+NIT1NO3OOA=...
     &   +                 RKI(   758 ) * YC ( NIT1NO3OOB   )   ! HO2+NIT1NO3OOB=RNO3I
     &   +                 RKI(   765 ) * YC ( NIT1OHOO     )   ! HO2+NIT1OHOO=R6OOH
     &   +                 RKI(   770 ) * YC ( DIBOO        )   ! HO2+DIBOO=R6OOH
     &   +                 RKI(   776 ) * YC ( MVKOO        )   ! HO2+MVKOO=ROOH
     &   +                 RKI(   781 ) * YC ( MACROO       )   ! HO2+MACROO=ROOH
     &   +    5.6000D-01 * RKI(   786 ) * YC ( MACO3        )   ! HO2+MACO3=...
     &   +                 RKI(   828 ) * YC ( IMACO3       )   ! HO2+IMACO3=...

      L5    = 1.0D0 + L5 * DTC + R4_5 + R21_5

c..HONO loss terms not included in R4_19
      L19 =                 RKI(    24 ) * YC ( OH           )   ! HONO+OH=NO2

      L19   = 1.0D0 + L19 * DTC + R4_19

c..HNO4 loss terms not included in R5_21
      L21 =    3.9000D-01 * RKI(    34 )                         ! HNO4=0.6100D+...
     &    +                 RKI(    35 ) * YC ( OH           )   ! HNO4+OH=NO2

      L21   = 1.0D0 + L21 * DTC + R5_21

ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c  Solution section
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc

c..compute terms used to calculate a,b & c
      L21_INV = 1.0D0 / L21
      T1 = 1.0D0 / ( L4 * L19 - R4_19 * R19_4 )
      T2 = R5_4 * T1
      T3 = R5_21 * L21_INV

c..solve quadratic equation for HO2
      A = 2.0D0 * ( RKI(    37 ) + RKI(    38 ) ) * DTC

      B = L5 - T3 * R21_5 - T2 * R4_5 * L19

      C = P5 + T3 * P21 + T2 * ( P4 * L19 + P19 * R4_19 )

      Q = -0.5D0 * ( B + SIGN( 1.0D0, B ) * SQRT( B * B + 4.0D0 * A * C ) )

      YCP( HO2 ) = MAX( Q / A , -C / Q  )

c..compute remaining species concentrations
      YCP( OH ) = ( ( P4 + R4_5 * YCP( HO2 ) ) * L19 + R4_19 * P19 ) * T1

      YCP( HNO4 ) = ( P21 + R21_5 * YCP( HO2 ) ) * L21_INV

      YCP( HONO ) = ( P19 + R19_4 * YCP( OH ) ) / L19

      RETURN

      END


